package cn.zealon.readingcloud.book.service.impl.createthread;

import cn.zealon.readingcloud.book.service.CollectService;
import cn.zealon.readingcloud.common.pojo.book.Book;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class ThreadToCollection extends Thread{
    private static Logger log = LoggerFactory.getLogger(ThreadToCollection.class);
    private Book[] books;

    private CollectService collectService;
    public ThreadToCollection(Book[] books,CollectService collectService){
        this.books=books;
        this.collectService=collectService;
    }
    @Override
    public void run() {
        log.debug("开始新的线程回推Book数据！");
        for (int i = 0; i < books.length; i++) {
            Book book = books[i];
            String bookJson = JSONObject.toJSONString(book);
            collectService.inputBooksToES(bookJson);
            log.debug("书名:"+book.getBookName()+"已经推送到ES");
        }

    }
}
